<!-- eslint-disable vue/no-parsing-error -->
<template>
  <div class="find-head">
    <!-- 找房的头部 -->
    <div>
      <van-nav-bar title="城市列表" left-arrow />
    </div>
    <!-- 找房搜索框 -->
    <div class="search-top">
      <van-search
        show-action
        left-icon="arrow-down"
        v-model="value"
        placeholder="请输入小区或地址"
      >
        <template #label>
          <span class="city" @click-left="$router.back()">上海</span>
          <span class="line"></span>
        </template>
        <template #action>
          <van-icon
            name="location-o"
            size="20"
            color="skyblue"
            @click="$router.push('/map')"
          />
        </template>
      </van-search>
    </div>
    <!-- 标签栏 -->
    <!-- 1:van-sticky让下拉菜单一直在上面 -->
    <van-sticky>
      <van-dropdown-menu active-color="#21b97a">
        <van-dropdown-item title="区域" ref="quxiao">
          <van-picker
            @cancel="onCancel"
            show-toolbar
            toolbar-position="bottom"
            :columns="columns"
          />
        </van-dropdown-item>
        <van-dropdown-item title="方式" ref="quxiao1">
          <van-picker
            @cancel="onCancel"
            show-toolbar
            toolbar-position="bottom"
            :columns="columns1"
          />
        </van-dropdown-item>
        <van-dropdown-item title="租金" ref="quxiao2">
          <van-picker
            @cancel="onCancel"
            show-toolbar
            toolbar-position="bottom"
            :columns="columns2"
          />
        </van-dropdown-item>
        <van-dropdown-item title="筛选" @open="show = true">
        </van-dropdown-item>
      </van-dropdown-menu>
    </van-sticky>
    <!-- <div style="height: 2000px"></div> -->
    <van-popup
      v-model="show"
      position="right"
      :style="{ height: '130%', width: '80% ' }"
    >
      <div class="houseType">
        <dl>
          <dt>户型</dt>
          <dd>
            <span v-for="(item, index) in roomType" :key="index">{{
              item
            }}</span>
          </dd>
        </dl>
        <dl>
          <dt>朝向</dt>
          <dd>
            <span>一室</span>
            <span>二室</span>
            <span>三室</span>
            <span>四室</span>
            <span>四室+</span>
          </dd>
        </dl>
        <dl>
          <dt>户型</dt>
          <dd>
            <span>一室</span>
            <span>二室</span>
            <span>三室</span>
            <span>四室</span>
            <span>四室+</span>
          </dd>
        </dl>
        <dl>
          <dt>户型</dt>
          <dd>
            <span>一室</span>
            <span>二室</span>
            <span>三室</span>
            <span>四室</span>
            <span>四室+</span>
          </dd>
        </dl>
        <van-sticky :offset-top="600">
          <van-button type="info">吸顶距离</van-button>
        </van-sticky>
      </div>
    </van-popup>
    <!-- <div class="fist-tab">
      <div class="second-tab" @click="quyu">
        <span ref="quyu">区域</span>
        <i></i>
      </div>
      <div>
        <span>方式</span>
        <i></i>
      </div>
      <div>
        <span>租金</span>
        <i></i>
      </div>
      <div class="saixuan">
        <i></i>
        <van-cell @click="showPopup"><span>筛选</span></van-cell>
        <van-popup
          v-model="show"
          position="right"
          :style="{ height: '100%', width: '70%' }"
          ><dl>
            <dt>户型</dt>
            <dd>
              <span>一室</span><span>一室</span><span>一室</span
              ><span>一室</span>
            </dd>
          </dl>
        </van-popup>
      </div>
    </div> -->

    <!-- <van-picker
      v-show="flag"
      :columns="columns"
      toolbar-position="bottom"
      :show-toolbar="true"
      @cancel="flag = false"
      @confirm="showPicker = false"
    >
      <template #default>
        <van-button plain type="primary" block @click="flag = false"
          >取消</van-button
        >
        <van-button type="primary" size="large">确定</van-button>
      </template>
    </van-picker> -->

    <!-- 房源信息 -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div
        class="house-mag"
        v-for="(item, index) in list"
        :key="index"
        @click="HouseList(item)"
      >
        <div class="pic-home"><img :src="item.houseImg" alt="" /></div>
        <div class="tex-home">
          <h4>{{ item.title }}</h4>
          <p class="first">
            <span>{{ item.desc }}</span>
            <span> 上海豪园 </span>
          </p>
          <p class="second">{{ item.tags[0] }}</p>
          <p class="three">
            <span>{{ item.price }}</span> <span class="four">元/月</span>
          </p>
        </div>
        <!-- <House :item="item"></House> -->
      </div>
    </van-list>
    <!-- 房源详情页 -->
  </div>
</template>

<script>
import { houseList, houseCondition } from '@/api/house'

// import House from '@/views/house.vue'
export default {
  name: 'find-page',
  async created() {
    // const {
    //   data: {
    //     body: { list }
    //   }
    // } = await houseList({ cityId: 'AREA|88cff55c-aaa4-e2e0' })
    // // 拿到数据，把数据给到data
    // list.map((item) => {
    //   item.houseImg = 'http://liufusong.top:8080' + item.houseImg
    //   return item
    // })
    // // console.log(list)
    // this.list = list
    // console.log(this.list)
    // 拿到下来里面的数据
    const res = await houseCondition({ id: 'AREA|88cff55c-aaa4-e2e0' })
    // 先处理第一个地铁这些的
    console.log(res.data)
    this.columns = res.data.body.subway.children
    console.log(this.columns)
    // console.log(res.data.body.rentType)
    this.columns1 = res.data.body.rentType.map((item) => (item = item.label))
    // console.log(this.columns1)
    this.columns2 = res.data.body.price.map((item) => (item = item.label))
    this.roomType = res.data.body.roomType.map((item) => (item = item.label))
    console.log(res.data.body)
  },
  data() {
    return {
      value: '',
      columns: [],

      // [
      //   {
      //     text: '浙江',
      //     children: [
      //       {
      //         text: '杭州',
      //         children: [{ text: '西湖区' }, { text: '余杭区' }]
      //       },
      //       {
      //         text: '温州',
      //         children: [{ text: '鹿城区' }, { text: '瓯海区' }]
      //       }
      //     ]
      //   },
      //   {
      //     text: '福建',
      //     children: [
      //       {
      //         text: '福州',
      //         children: [{ text: '鼓楼区' }, { text: '台江区' }]
      //       },
      //       {
      //         text: '厦门',
      //         children: [{ text: '思明区' }, { text: '海沧区' }]
      //       }
      //     ]
      //   }
      // ],
      columns1: [],
      columns2: ['不限', '1000及以下', '1000-2000'],
      roomType: [],
      show: false,
      list: [],
      loading: false,
      finished: false
    }
  },
  methods: {
    // pic点取消关闭的按键
    onCancel() {
      this.$refs.quxiao.toggle(false)
      this.$refs.quxiao1.toggle(false)
      this.$refs.quxiao2.toggle(false)
    },
    // 让房源列表多次加载
    async onLoad() {
      // 计算机打开的一瞬间是没有数据的，所以直接打开就是到底部了
      console.log('到底部le')
      const {
        data: {
          body: { list }
        }
      } = await houseList({ cityId: 'AREA|88cff55c-aaa4-e2e0' })
      // 拿到数据，把数据给到data
      list.map((item) => {
        item.houseImg = 'http://liufusong.top:8080' + item.houseImg
        return item
      })
      // console.log(list)
      this.list.push(...list)
      // console.log(this.list)
      this.loading = false
    }
    // HouseList(obj) {
    //   this.$router.push('/house')
    //   // 点击的时候把这一个对象全部给到house，怎么改 第一种保存到本地，第二种，
    //   // 再建一个data空对象，传给house
    //   window.localStorage.setItem('houseDetails', JSON.stringify(obj))
    // },
  },
  components: {}
}
</script>

<style scoped lang="less">
.find-head {
  position: relative;
  .search-top {
    position: fixed;
    top: 7px;
    left: 40px;
    // width: 100%;
    width: 300px;
    z-index: 99;
    // background-color: transparent;
    .van-search {
      height: 35px;
    }
  }
}
.fist-tab {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 40px;
  .second-tab {
    ::v-deep span::after {
      content: '';
      width: 0;
      height: 0;
      display: block;
      border: 6px solid transparent;
      border-top-color: #000;
      position: absolute;
      top: 6px;
      right: -16px;
    }
  }
}
.van-button:first-child {
  border-color: #ccc;
  height: 50px;
  width: 125px;
}
// 房源信息颜色
.house-mag {
  display: flex;
  .pic-home {
    width: 106px;
    height: 80px;
    margin-right: 15px;
    img {
      width: 100%;
    }
  }
  .tex-home {
    margin-top: 10px;
  }
  .first {
    color: #afb2b3;
    font-size: 15px;
  }
  .second {
    width: 50px;
    height: 20px;
    background-color: #e1f5f8;
    color: #39becd;
    font-size: 15px;
  }
  .three {
    color: red;
    span:first-child {
      font-size: 18px;
      font-weight: 700;
    }
    span:last-child {
      font-size: 14px;
    }
  }
}

::v-deep .van-picker__cancel {
  height: 50px;
  width: 125px;
  color: #85b97a;
  background-color: #fff;
}
::v-deep .van-picker__confirm {
  height: 50px;
  width: 250px;
  color: #fff;
  background-color: #21b97a;
}
// 房源导航
.houseType {
  dt {
    margin: 20px 0;
    margin-left: 10px;
    font-size: 15px;
  }
  dd {
    display: block;
    margin: 0 50px;
    display: flex;
    flex-direction: row;
    margin-top: 10px 0 0 10px;
    // justify-content: space-around;
    // margin-inline-start: 40px;
    // align-items: center;
    flex-wrap: wrap;
    width: 225px;
    height: 156px;
    border-bottom: 1px solid #e5e5e5;

    span {
      display: inline-block;
      width: 70px;
      height: 30px;
      margin: 0 18px 15px 0;
      border-radius: 3px;
      line-height: 32px;
      text-align: center;
      border: 1px solid #ddd;
      font-size: 14px;
      border-radius: 3px;
    }
  }
}
</style>
